import pymysql

class MysqlHelper(object):
    def __init__(self,host,user,password,dbname,charset='utf8',port=3306):
        self.host = host
        self.port = port
        self.user=user
        self.password = password
        self.dbname = dbname
        self.charset = charset


    def open(self):
      self.conn = pymysql.connect(
          host=self.host,
          port=self.port,
          user=self.user,
          password=self.password,
          database=self.dbname,
          charset=self.charset,
      )
      self.cursor = self.conn.cursor()

    def close(self):
        self.cursor.close()
        self.conn.close()


    def iud(self,sql,param):
        self.cursor.execute(sql,param)
        self.conn.commit()

    def read(self,sql,param):
        self.cursor.execute(sql,param)
        result = self.cursor.fetchall()
        return  result


